#ifndef SYSYF_ACTIVEVAR_H
#define SYSYF_ACTIVEVAR_H

#include "Pass.h"
#include "Module.h"
#include <list>
#include <vector>
#include <memory>
#include <set>
#include <map>

class ActiveVar : public Pass
{
public:
    ActiveVar(Module *module) : Pass(module) {}
    void execute() final;
    const std::string get_name() const override {return name;}
    void get_revserse_post_order(Function* f);
    void get_post_order(BasicBlock* bb,std::set<BasicBlock*>& visited);
    void get_bb_live(Function* f);
    void get_def_use();
    void set_bb_live();
    void print_info();
private:
    struct use_item{
        Value *op;
        BasicBlock *bb;
    };
    Function *func_;
    const std::string name = "ActiveVar";
    std::list<BasicBlock*> reverse_post_order;
    std::map<BasicBlock*,int> bb2int;
    std::vector<std::set<Value*>> bb_def;
    std::vector<std::set<Value*>> bb_use;
    std::vector<std::set<Value*>> bb_in;
    std::vector<std::set<Value*>> bb_out;
    std::vector<std::set<Value*>> bb_phi;
    Type *VOID_T;
};

#endif  // SYSYF_ACTIVEVAR_H